import os
import pandas as pd
from settings import TESTDATA_DIR
from psa.log import logger


class FileData:

    @staticmethod
    def get_from_json(json_name, keys): 
        file_path = os.path.join(TESTDATA_DIR, "json", json_name)
        logger.info("Get Data From {}".format(file_path))
        df = pd.read_json(file_path)
        data = df.loc[:, keys].values.tolist()
        return data
    
    @staticmethod
    def get_from_csv(csv_name, keys): 
        file_path = os.path.join(TESTDATA_DIR, "csv", csv_name)
        logger.info("Get Data From {}. keys:{}".format(file_path, keys))
        df = pd.read_csv(file_path)
        data = df.loc[:, keys].values.tolist()
        return data
    
    @staticmethod
    def get_from_excel(excel_name, case_name, keys): 
        file_path = os.path.join(TESTDATA_DIR, "excel", excel_name)
        logger.info("Get Data From {}".format(file_path))
        df = pd.read_excel(file_path)
        df = df.loc[df['case_name'] == case_name]
        data = df.loc[:, keys].values.tolist()
        return data

